cmake_minimum_required(VERSION 3.10)
project(snippets_tests)

set(TARGET snippets_tests)

# 基础测试文件（无条件包含）
file(GLOB TEST_SOURCES
    "main.cc"
    "smart_pointer/*.cc"
    "state_machine/v1/*.cc"
)

if(ENABLE_BEHAVIOR_TREE)
    file(GLOB BT_TEST_SOURCES
        "behavior_tree/*.cc"  # 行为树测试用例
    )
    list(APPEND TEST_SOURCES ${BT_TEST_SOURCES})
endif()

# 收集被测源码（无条件包含通用模块）
file(GLOB COMMON_SOURCES
    "${PROJECT_SOURCE_DIR}/../src/smart_pointer/*.cc"
    "${PROJECT_SOURCE_DIR}/../src/thread_pool/*.cc"
    "${PROJECT_SOURCE_DIR}/../src/type_traits_demo/*.cc"
    "${PROJECT_SOURCE_DIR}/../src/state_machine/v1/*.cc"
    "${PROJECT_SOURCE_DIR}/../src/state_machine/v2/*.cc"
)

# 条件包含行为树被测源码
set(SRC_FILES_TO_TEST ${COMMON_SOURCES})
if(ENABLE_BEHAVIOR_TREE)
    file(GLOB BT_SOURCES
        "${PROJECT_SOURCE_DIR}/../src/behavior_tree/*.cc"
    )
    list(APPEND SRC_FILES_TO_TEST ${BT_SOURCES})
endif()

# 创建测试可执行文件
add_executable(${TARGET} ${TEST_SOURCES} ${SRC_FILES_TO_TEST})

# 基础测试框架链接
target_link_libraries(${TARGET}
    GTest::GTest
    GTest::Main
    pthread
)

# 条件链接行为树库
if(ENABLE_BEHAVIOR_TREE)
    target_link_libraries(${TARGET} behaviortree_cpp)
endif()